/*
 *
 * author: fernado
 * create date: 2011-5-7
 */

package iceworld.fernado.app;

import iceworld.fernado.entity.Table;
import iceworld.fernado.file.impl.CsharpSaveResource;
import iceworld.fernado.file.impl.JavaSaveResource;
import iceworld.fernado.file.impl.LoadResource;
import iceworld.fernado.file.impl.XmlSaveResource;

import java.util.Map;
import java.util.Scanner;

public class Application {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		LoadResource lr = new LoadResource();
		lr.readResources();
		Map<String, Table> tables = lr.getTables();
		CsharpSaveResource csr = new CsharpSaveResource();
		csr.removeResources();
		for (Map.Entry<String, Table> me: tables.entrySet()) {
			String tableName = me.getKey();
			Table table = me.getValue();
			csr.saveResources(tableName, table.getFields());
		}
		XmlSaveResource xsr = new XmlSaveResource();
		xsr.removeResources();
		for (Map.Entry<String, Table> me: tables.entrySet()) {
			String tableName = me.getKey();
			Table table = me.getValue();
			xsr.saveResources(tableName, table.getFields());
		}
		
	}
	
	private static void second(String[] args) {
		if (args.length < 1) {
			System.out.println("Please input the parameter! eg: java|csharp");
			System.out.println("exit: exit");
		}
		if (args.length > 1) {
			System.out.println("Please input only one parameter! eg: java|csharp");
			System.out.println("exit: exit");
		}
		
		Scanner scan = new Scanner(System.in);
		String param = scan.next();
		if ("exit".equals(param)) {
			return;
		}
		while (!"java".equals(param) && !"csharp".equals(param)) {
			System.out.println("Please input only one parameter! eg: java|csharp");
			System.out.println("exit: exit");
			param = scan.next();
			if ("java".equals(param) || "csharp".equals(param)) {
				break;
			}
			if ("exit".equals(param)) {
				return;
			}
		}
		
		LoadResource lr = new LoadResource();
		lr.readResources();
		if ("java".equals(param)) {
			Map<String, Table> tables2 = lr.getTables();
			JavaSaveResource jsr = new JavaSaveResource();
			jsr.removeResources();
			for (Map.Entry<String, Table> me: tables2.entrySet()) {
				String tableName = me.getKey();
				Table table = me.getValue();
				jsr.saveResources(tableName, table.getFields());
			}
		}
		if ("csharp".equals(param)) {
			Map<String, Table> tables = lr.getTables();
			CsharpSaveResource csr = new CsharpSaveResource();
			csr.removeResources();
			for (Map.Entry<String, Table> me: tables.entrySet()) {
				String tableName = me.getKey();
				Table table = me.getValue();
				csr.saveResources(tableName, table.getFields());
			}
			XmlSaveResource xsr = new XmlSaveResource();
			xsr.removeResources();
			for (Map.Entry<String, Table> me: tables.entrySet()) {
				String tableName = me.getKey();
				Table table = me.getValue();
				xsr.saveResources(tableName, table.getFields());
			}
		}
	}
}
